package com.xiaoming.e3mall.controller;

import com.xiaoming.e3mall.pojo.Item;
import com.xiaoming.e3mall.pojo.TbItem;
import com.xiaoming.e3mall.pojo.TbItemDesc;
import com.xiaoming.e3mall.service.ItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class ItemController {

    @Autowired
    private ItemService itemService;

    @RequestMapping("/item/{itemId}")
    public String showItemInfo(@PathVariable Long itemId, Model model){
        //调用服务取商品的基本信息
        TbItem tbItem = itemService.getItemById(itemId);
        Item item = new Item(tbItem);

        //取商品的描述信息
        TbItemDesc itemDesc = itemService.getTbItemDescById(itemId);
        //把信息传递给页面
        model.addAttribute("item", item);
        model.addAttribute("itemDesc", itemDesc);

        //返回逻辑视图
        return "item.jsp";
    }

}
